﻿using System.Windows;
using YourLastOptionsDialog.ViewModels.Options;
using YourLastOptionsDialog.Views;

namespace YourLastOptionsDialog
{
    /// <summary>
    /// Implements the <see cref="IOptionsViewFactory"/> interface to provide 
    /// additional views for <see cref="TimeSpanOption"/> and <see cref="ColorOption"/> instances.
    /// </summary>
    public class ExtrasOptionsViewFactory : IOptionsViewFactory
    {
        private readonly DefaultOptionsViewFactory _defaultFactory = new DefaultOptionsViewFactory();

        #region Implementation of IOptionsViewFactory

        /// <summary>
        /// Creates a view for a given option instance.
        /// </summary>
        /// <param name="option">The option to create the view for.</param>
        /// <returns>A framework element that is able to edit the given option.</returns>
        public FrameworkElement CreateViewFor(Option option)
        {
            FrameworkElement result = null;

            if (option is TimeSpanOption)
            {
                result = new TimeSpanEditor();
            }
            else if (option is ColorOption)
            {
                result = new ColorEditor();
            }

            // are we supporting this kind of option?
            if (result != null)
            {
                result.DataContext = option;
                return result;
            }

            // for each option type we don't support, let the default factory handle it
            return _defaultFactory.CreateViewFor(option);
        }

        #endregion
    }
}
